﻿using Microsoft.Phone.Shell;

namespace Microsoft.Phone.Controls
{
    /// <summary>
    /// Bindable alternative implementation of <see cref="IApplicationBarMenuItem">MenuItem</see>.
    /// </summary>
    public class ApplicationBarMenuItemHost : ApplicationBarMenuItemHost<ApplicationBarMenuItem>
    {

    }

    /// <summary>
    /// Bindable alternative generic implementation of <see cref="IApplicationBarMenuItem">MenuItem</see>.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class ApplicationBarMenuItemHost<T> : ApplicationBarItemBase
        where T : ApplicationBarMenuItem, new()
    {
        private readonly T _menuItem;

        /// <summary>
        /// Gets <see cref="ApplicationBarMenuItem">MenuItem</see>.
        /// </summary>
        public T MenuItem
        {
            get { return _menuItem; }
        }

        /// <summary>
        /// .ctor
        /// </summary>
        protected ApplicationBarMenuItemHost()
        {
            _menuItem = new T {Text = "?"};
            _menuItem.Click += OnClick;
        }

        #region Overrides of ApplicationBarMenuItemHostBase

        /// <summary>
        /// Processes Text property changes.
        /// </summary>
        /// <param name="text"></param>
        protected override void OnTextChanged(string text)
        {
            MenuItem.Text = text;
        }

        /// <summary>
        /// Processes IsEnabled property changes.
        /// </summary>
        /// <param name="isEnabled"></param>
        protected override void OnIsEnabledChanged(bool isEnabled)
        {
            MenuItem.IsEnabled = isEnabled;
        }

        #endregion
    }
}